package game.players.cpu.opponent;

import java.util.Timer;

import utils.tasks.ExpireTask;
import game.ball.Possessed;
import game.players.SoccerPlayer;
import game.players.states.WithBall;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.appearances.Sprite;

public class CornerKickerThrowInerCPUOpp extends WithBall{
	
	private boolean ready = false;

	public CornerKickerThrowInerCPUOpp(SoccerPlayer player) {
		super(player);
		this.getPlayer().setAppearance(Sprite.fromImage("/images/goal3_caminando3.png").crop(0, 1, 34, 65).scale(1.5).flipHorizontally());
		player.getScene().getSoccerBall().setState(new Possessed(player));
		this.setTeammates(this.getPlayer().getScene().getOpponents());
		this.setSoccerBall(this.getPlayer().getScene().getSoccerBall());
		Timer timer = new Timer();
		timer.schedule(new ExpireTask<CornerKickerThrowInerCPUOpp>(this) {

			@Override
			public void run() {
				this.getCallBackClass().setReady(true);
			}
			
		}, 3000);
	}

	@Override
	public void update(DeltaState deltaState) {
		if(this.ready) {
			this.getPlayer().setState(new PassingCPUOppPlayer(this.getPlayer(), this.getClosestMate()));
			this.getPlayer().getScene().setBallOnGame(true);
		}
	}

	@Override
	public boolean isRight() {
		return true;
	}

	@Override
	public void loseTheBall() {
		// no puede perder la pelota si esta sacando el corner		
	}
	
	public void setReady(boolean ready) {
		this.ready = ready;
	}

}
